% To calculate percentage from counted transtion matrices
clear all;
clc;
load 01_04.mat
freqj=12;% 12 months
year_list=[2001:2004]';
year_list_text=num2str(year_list);
month_list=[1:12]';
month_list_text=num2str(month_list);
Rate_list=[0,1:0.5:5];
prob=zeros(4,freqj,10,13);
prob_std=zeros(4,freqj,10,12);
default_prob=zeros(length(year_list)*freqj,1);
filename='prob_std_0104.xls';

for i=1:4
for j=1:freqj
    for ii=1:length(Rate_list)
        for jj=1:12
            prob(i,j,ii,jj) = final_result(i,j,ii,jj)/final_result(i,j,ii,13);            
        end
    end 
end 
end 

for i=1:4
    for j=1:freqj
        for ii=1:length(Rate_list)
            for jj=1:12
                prob_std(i,j,ii,jj) = prob(i,j,ii,jj)/(1-prob(i,j,ii,12));
            end
        end
        xx(:,:)=prob_std(i,j,:,:);
        sheetlist=strcat('',year_list_text(i,:),'.',month_list_text(j,:),'');
        xlswrite(filename, xx, sheetlist);
        clear xx sheetlist
    end
end

ij=1;
for i=1:4
    for j=1:freqj
           default_prob(ij,1)=(sum(final_result(i,j,1:10,11))/sum(final_result(i,j,1:10,13)))/(1-(sum(final_result(i,j,1:10,12))/sum(final_result(i,j,1:10,13))));
           ij=ij+1;
     end
end
xx(:,:)=default_prob(:,1); 
xlswrite(filename, xx, 'default_prob');


